package org.wjw.udp;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;

public class UDPDictServer extends UDPEchoServer {
    //创建一个字典
    Map<String, String> map;

    //在构造方法中初始化字典内容
    public UDPDictServer(int port) throws SocketException {
        super(port);
        map = new HashMap<>();
        map.put("tiger", "老虎");
        map.put("cat", "小猫");
        map.put("dog", "小狗");
        map.put("pig", "小猪");
        map.put("very good", "牛P");
    }

    @Override
    protected String process(String request) {
        return map.getOrDefault(request, "查无此词");
    }

    public static void main(String[] args) throws IOException {
        UDPDictServer udpDictServer = new UDPDictServer(9090);
        udpDictServer.start();
    }
}
